import { ref, onMounted } from 'vue'
import { getCategoryAPI } from '@/apis/category'
import { onBeforeRouteUpdate, useRoute } from 'vue-router' 

export function useCategory () {
    const cateGoryData = ref({})
    const route = useRoute()
    const getcateGoryData = async (id = route.params.id) => {
        const res = await getCategoryAPI(id)
        cateGoryData.value = res.result
    }

    onBeforeRouteUpdate((to) => {
        getcateGoryData(to.params.id)
    })

    onMounted(() => getcateGoryData())

    return cateGoryData
}